<template>
  <!-- 轮播图部分 -->
  <div class="banner-container">
    <div class="swiper-container">
      <div class="swiper-wrapper">
        <div
          v-for="(item, index) in bannerData"
          :key="index"
          class="swiper-slide banner-slide"
        >
          <div class="banner-img">
            <img :src="baseUrl + item.imageUrl" :alt="item.title" />
          </div>
          <div class="banner-content">
            <h1 class="banner-title">{{ item.title }}</h1>
            <span class="divider-line" v-if="item.title"></span>
            <div class="banner-subtitle">
              <span>{{ item.subtitle }}</span>
            </div>
            <button
              v-if="!item.showButton"
              @click="handleRedirect(item.buttonLink)"
              class="detail-button"
            >
              {{ item.buttonText }}
            </button>
          </div>
        </div>
      </div>
      <!-- 分页器 -->
<!--      <div class="swiper-pagination"></div>-->
    </div>
  </div>
</template>

<script>
import Swiper from 'swiper';
import 'swiper/css/swiper.min.css';

export default {
  props: {
    bannerData: {
      type: Array,
      default: () => []
    }
  },
  computed: {
    baseUrl() {
      return process.env.VUE_APP_BASE_API
    }
  },
  mounted() {
    this.initSwiper();
  },
  watch: {
    bannerData() {
      this.$nextTick(() => {
        this.initSwiper();
      });
    }
  },
  methods: {
    initSwiper() {
      if (this.swiper) {
        this.swiper.destroy();
      }

      this.swiper = new Swiper('.swiper-container', {
        loop: true,
        autoplay: {
          delay: 2000,
          disableOnInteraction: false,
        },
        pagination: {
          el: '.swiper-pagination',
          clickable: true,
        },
        effect: 'fade',
        speed: 1000,
      });
    },
    handleRedirect(link) {
      this.$router.push(link);
    }
  }
}
</script>

<style scoped lang="scss">
/* 轮播图样式 */
.banner-container {
  position: relative;
  width: 100%;
  max-height: 800px;
  overflow: hidden;
}

.swiper-container {
  width: 100%;
  height: 100%;
}

.banner-slide {
  position: relative;
  width: 100%;
  height: 100%;
}

.banner-img img {
  width: 100%;
  height: 100%;
  min-height: 500px;
  object-fit: cover;
}

.banner-content {
  position: absolute;
  top: 60%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: white;
  width: 100%;
  padding: 0 20px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.banner-title {
  font-size: 56px;
  font-weight: bold;
  margin-bottom: 1rem;
}

.divider-line {
  height: 3px;
  width: 300px;
  background-color: white;
  display: inline-block;
  margin-bottom: 20px;
}

.banner-subtitle {
  font-size: 1.2rem;
  margin-bottom: 2rem;
}

.detail-button {
  margin-top: 110px;
  color: white;
  border: none;
  background-color: #fe3231;
  padding: 16px 40px;
  font-size: 1rem;
  border-radius: 30px;
  cursor: pointer;
  transition: all 0.3s ease;

  &:hover {
    background-color: darken(#fe3231, 10%);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  }
}

/* 分页器样式 */
.swiper-pagination {
  position: absolute;
  bottom: 30px;
  left: 0;
  width: 100%;
  text-align: center;
  z-index: 10;
}

.swiper-pagination-bullet {
  width: 12px;
  height: 12px;
  background: rgba(255, 255, 255, 0.5);
  margin: 0 8px;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.3s ease;
  display: inline-block;
}

.swiper-pagination-bullet-active {
  background: white;
  transform: scale(1.2);
}

/* 媒体查询：小屏幕平板和手机 */
@media (max-width: 768px) {
  .banner-container {
    max-height: 400px; /* 移动端最大高度减小 */
    overflow: hidden;
  }

  .banner-img img {
    min-height: 300px; /* 移动端最小高度减小 */
  }

  .banner-content {
    top: 60%; /* 内容位置更居中 */
    width: 90%; /* 内容宽度减小以适应小屏幕 */
    padding: 0 15px;
  }

  .banner-title {
    font-size: 28px; /* 移动端标题字体减小 */
    margin-bottom: 0.5rem;
  }

  .divider-line {
    width: 150px; /* 移动端分隔线宽度减小 */
    margin-bottom: 10px;
  }

  .banner-subtitle {
    font-size: 1rem; /* 移动端副标题字体减小 */
    margin-bottom: 1rem;
  }

  .detail-button {
    margin-top: 10px; /* 移动端按钮外边距减小 */
    padding: 12px 24px; /* 移动端按钮内边距减小 */
    font-size: 0.9rem; /* 移动端按钮字体减小 */
    border-radius: 20px; /* 移动端按钮圆角减小 */
  }

  .detail-button:hover {
    transform: translateY(-1px); /* 移动端按钮悬停效果减小 */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); /* 移动端按钮阴影减小 */
  }

  .swiper-pagination {
    bottom: 20px; /* 移动端分页器位置更靠上 */
  }

  .swiper-pagination-bullet {
    width: 8px; /* 移动端分页器小圆点减小 */
    height: 8px;
    margin: 0 5px;
  }
}

/* 媒体查询：小屏幕手机 */
@media (max-width: 480px) {
  .banner-container {
    max-height: 300px; /* 更小屏幕最大高度进一步减小 */
  }

  .banner-title {
    font-size: 24px; /* 更小屏幕标题字体进一步减小 */
    margin-bottom: 0.4rem;
  }

  .divider-line {
    width: 120px; /* 更小屏幕分隔线宽度进一步减小 */
  }

  .banner-subtitle {
    font-size: 0.9rem; /* 更小屏幕副标题字体进一步减小 */
  }

  .detail-button {
    margin-top: 10px; /* 更小屏幕按钮外边距进一步减小 */
    padding: 10px 20px; /* 更小屏幕按钮内边距进一步减小 */
    font-size: 0.8rem; /* 更小屏幕按钮字体进一步减小 */
    border-radius: 15px; /* 更小屏幕按钮圆角进一步减小 */
  }
}
</style>
